﻿@using ShowPin.MvcPaging
@model PaginationModel


@BuildLink()


@helper  BuildLink()
{
    var ul = new TagBuilder("ul");
    ul.MergeAttributes(Model.Options.HtmlAttributes);
    foreach (var link in Model.PaginationLinks)
    {
        var liBuilder = new TagBuilder("li");
        if (link.IsCurrent)
        {
            liBuilder.MergeAttribute("class", "active");
        }
        if (!link.IsEnabled)
        {
            liBuilder.MergeAttribute("class", "disabled");
        }

        var aBuilder = new TagBuilder("a");
        aBuilder.MergeAttribute("href", link.Url ?? "javascript:");

        // Ajax support
        if (Model.AjaxOptions != null)
        {
            foreach (var ajaxOption in Model.AjaxOptions.ToUnobtrusiveHtmlAttributes())
            {
                aBuilder.MergeAttribute(ajaxOption.Key, ajaxOption.Value.ToString(), true);
            }
        }


        switch (link.DisplayText)
        {
            case "«":
                aBuilder.SetInnerText("←");
                break;
            case "»":
                aBuilder.SetInnerText("→");
                break;
            default:
                aBuilder.SetInnerText(link.DisplayText);
                break;
        }
        liBuilder.InnerHtml = aBuilder.ToString();
        ul.InnerHtml += liBuilder.ToString();
    }

    @Html.Raw(ul)
}
